package com.lg.partition12;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/6/5 10:16
 */
public class P1189SEARCH {

    private static final int[][] dirs = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
    private static final int N = 55, M = 1010;
    private static char[][] g = new char[N][N];
    private static boolean[][][] st = new boolean[M][N][N];
    private static char[] d = new char[M];
    private static int n, m, k, sx, sy;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] ss = reader.readLine().split(" ");
        n = Integer.parseInt(ss[0]); m = Integer.parseInt(ss[1]);
        for (int i = 0; i < n; i++) {
            String s = reader.readLine();
            for (int j = 0; j < m; j++) {
                g[i][j] = s.charAt(j);
                if (g[i][j] == '*') {
                    sx = i; sy = j;
                }
            }
        }
        k = Integer.parseInt(reader.readLine());
        for (int i = 0; i < k; i++) d[i] = reader.readLine().charAt(0);
        g[sx][sy] = '.';
        dfs(sx, sy, 0);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                writer.write(g[i][j]);
            }
            writer.write("\n");
        }
        writer.flush();
    }

    private static void dfs(int x, int y, int u) {
        if (st[u][x][y]) return;
        st[u][x][y] = true;
        if (u == k) {
            g[x][y] = '*';
            return;
        }
        int nd = get(d[u]), nx = x + dirs[nd][0], ny = y + dirs[nd][1];
        while (check(nx, ny)) {
            dfs(nx, ny, u + 1);
            nx += dirs[nd][0];
            ny += dirs[nd][1];
        }
    }

    private static boolean check(int x, int y) {
        return x >= 0 && y >= 0 && x < n && y < m && g[x][y] != 'X';
    }

    private static int get(char c) {
        if (c == 'N') return 0;
        if (c == 'E') return 1;
        if (c == 'S') return 2;
        return 3;
    }
}
